package tech.jabari.user.controller;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

import static tech.jabari.constants.UMSConstant.ACCESS_DENY_URL;
import static tech.jabari.constants.UMSConstant.USER_ID;

@WebServlet("/updateUser.action")
public class UpdateUserServlet extends HttpServlet {
    /**
     * 更新用户
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    /**
     * 显示用户详情html页面
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("id");
        if (id == null) {
            Object idObj = request.getSession().getAttribute(USER_ID);
            if (idObj != null) {
                id = idObj.toString();
            } else {
                response.sendRedirect(ACCESS_DENY_URL);
                return;
            }
        }
        response.sendRedirect("/detail.html?id=" + id);
    }
}
